package com.rui.controller;

import com.rui.dao.ManagerDao;
import com.rui.entity.Manager;
import com.rui.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by Administrator on 2017/4/18.
 */
@Controller
@RequestMapping("/common")
public class CommonController {
    private static final String MESSAGE = "message";

    @Autowired
    private ManagerService managerService;

    @RequestMapping("/login")
    public String login(Model model, String userName, String password){
        Manager manager = managerService.findByUserName(userName);
        if (manager == null) {
            model.addAttribute(MESSAGE, "用户名或密码错误");
            return "common/loginManager";
        } else {
            if (manager.getPassword().equals(password)) {
                return "common/indexManager";
            } else {
                model.addAttribute(MESSAGE, "用户名或密码错误");
                return "common/loginManager";
            }
        }
    }
}
